# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  https://gitee.com/autumner/pythoncookbook
@software: PyCharm 
@file: net_memoryviews_client.py 
@time: 2019/7/31 上午10:43
@note:
利用函数memoryviews来发送和接受大数组
"""

def recv_into(arr, source):
    '创建接收大数组函数'
    view = memoryview(arr).cast('B')
    while len(view):
        nrecv = source.recv_into(view)
        view = view[nrecv:]


from socket import *

# 创建socket客户端
c = socket(AF_INET, SOCK_STREAM)
c.connect(('localhost', 35000))


import numpy

# 接收大数组
arr = numpy.zeros(shape=50000000, dtype=float)
print(arr[0:10])
recv_into(arr, c)
print(arr[0:10])
c.close()